<?php 
include '../data/data.php';
$user=$_SESSION['user']; //获取到的用户名
$pass=$_SESSION['pass']; //获取到的密码
$result= mysql_query("SELECT * FROM user WHERE username='$user' and password='$pass'", $link);  
$row = mysql_fetch_array($result);
if($row[id]==''){
	header('location:/user/login.html?fwd=/user/tui.html');
}
if($_POST){
$oldpwd=md5($_POST[oldpwd]);
$newpwd=$_POST[newpwd];
$re_pwd=$_POST[re_pwd];
  if(empty($oldpwd) || empty($newpwd) || empty($re_pwd)){
  $returndata = array("msg"=>"请填写相关信息！","log"=>"false","fwd"=>"");
    exit(json_encode($returndata));
  }
  if($newpwd!=$re_pwd){
  $returndata = array("msg"=>"请核对新密码，密码不正确！","log"=>"false","fwd"=>"");
    exit(json_encode($returndata));
  }
  if($oldpwd!=$pass){
  $returndata = array("msg"=>"旧密码不正确！","log"=>"false","fwd"=>"");
    exit(json_encode($returndata));
  }
  $passc=md5($newpwd);
  mysql_query("UPDATE user SET password='$passc' WHERE username='$user' and password='$oldpwd'", $link); 
  unset($_SESSION['user']);
  unset($_SESSION['pass']);
  $returndata = array("msg"=>"修改成功,请重新登录！","log"=>"false","fwd"=>"/user/user.html");
    exit(json_encode($returndata));
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<title>修改密码 - 个人资料 - <?php echo $rowx[name]; ?></title>
<link rel="stylesheet" href="/public/styles/base.css"/>
<link rel="stylesheet" href="/styles/user_password.css"/>
    <link rel="stylesheet" href="/css/new.css"/>
</head>
<body class="bg00">
<!--div.container 总外框  start-->
<div class="z_container bg02" >
    <header class="z_header block_bg">
        <div class="toptil">
            <a href="/user/edit.html"><img src="/picture/icon_20.png" alt=""></a>
            <p>修改密码</p>
        </div>
    </header>

    <!--div.z_min 内容区域 statr-->
    <div class="z_main" data-role="conent">
        <form class="user_form">
            <div style="margin-top: 40px;">
                <img style="width: 12px;" src="/picture/icon_17.png" alt="">
                <input type="password" id="oldpwd" placeholder="旧密码" maxlength="16"/>
            </div>
            <div style="width: 100%;height: 1px;background: #f4f4f4;"></div>
            <div style="margin-top: 40px;">
                <img style="width: 12px;" src="/picture/icon_17.png" alt="">
                <input type="password" id="newpwd" placeholder="新密码" maxlength="16"/>
            </div>
            <div style="width: 100%;height: 1px;background: #f4f4f4;"></div>
            <div style="margin-top: 40px;">
                <img style="width: 12px;" src="/picture/icon_17.png" alt="">
                <input type="password" id="re_pwd" placeholder="确认新密码" maxlength="16"/>
            </div>
            <div style="width: 100%;height: 1px;background: #f4f4f4;"></div>
<!--            <input class="text" type="password" placeholder="旧密码" id="oldpwd"/>-->
<!--            <input class="text" type="password" placeholder="新密码" id="newpwd"/>-->
<!--            <input class="text" type="password" placeholder="确认新密码" id="re_pwd"/>-->
            <a class="login_btn" id="save" href="javascript:void(0)">确认</a>
<!--            <div class="service">-->
<!--                <i class="i_qq"></i>客服QQ:--><!--            </div>-->
        </form>
        <div class="footer_padding"></div>
    </div>
    <!--div.z_min 内容区域 end-->
</div>
<!--div.container 总外框  end-->
<!--footer 底部 start-->
<footer id="footer" class="z_footer" style="">
   <nav>
        <a target="_top" href="/index.html" style="margin-left: 2%;" >
            <p class="img_1"><img src="/picture/home.png" alt=""></p>
            <p class="img_2"><img src="/picture/home1.png" alt=""></p>
            <span>首页</span>
        </a>
        <a target="_top" href="/game/type.html?tc=GM" >
            <p class="img_1"><img src="/picture/game.png" alt=""></p>
            <p class="img_2"><img src="/picture/game1.png" alt=""></p>
            <span>GM</span>
        </a>
        <a target="_top" href="/game/game.html?tc=rm" title="">
            <p class="img_1"><img src="/picture/game.png" alt=""></p>
            <p class="img_2"><img src="/picture/game1.png" alt=""></p>
            <span>BT</span>
        </a>
        <a target="_top" href="/user/user.html" title="" >
            <p class="img_1"><img src="/picture/user.png" alt=""></p>
            <p class="img_2"><img src="/picture/user1.png" alt=""></p>
            <span>我的</span>
        </a>
    </nav>
</footer>
<link href="/css/app.css" rel="stylesheet" type="text/css">
<div id="weixin_an" style="display: none">
    <div class="click_opacity"></div>
    <div class="to_btn">
        <span class="span1"><img src="/public/channel/click_btn.png"></span>
        <span class="span2"><em>1</em> 点击右上角<img src="/public/channel/menu_android.png">打开菜单</span>
        <span class="span2 android_open"><em>2</em> 选择<img src="/public/channel/android.png"></span>
        <span class="span2 android_open"><em>3</em> 重新登录账号充值</span>
    </div>
</div>

<!--二维码-->
<script src="/public/scripts/jquery-1.11.1.min.js"></script>
<script src="/public/scripts/jquery.qrcode.min.js"></script>

<!--<div class="qrcode_image">-->
<!--        <img src="/qrcode/game.html?addr=--><!--">-->
<!--</div>-->

<script src="/public/scripts/jquery-1.11.1.min.js"></script>
<script src="/public/scripts/jquery.mobile.min.js"></script>
<script>
$('#footer a:eq(5)').attr('id', 'footer_nav_active');
$(function(){
    /**修改默认输入框失去焦点事件样式*/
    $(".user_form input").blur(function(){
    	var _t = $(this);
        var v = $.trim(_t.val());
        if(v != ""){
            _t.css("color","#fff");
        } else {
        	_t.css("color","#3c555e");
        }
    	$('#footer').show();
    }).focus(function(){
        $(this).css("color","#fff");
    	$('#footer').hide();
    });

    var loading = false;
    $('#save').on('tap', function(){
        if( loading ) return false;
        var o = $.trim($('#oldpwd').val());
        var n = $.trim($('#newpwd').val());
        var r = $.trim($('#re_pwd').val());
        if( o.length < 6 ) {
            alert('请输入你的旧密码！');
            $('#oldpwd').focus();
            return false;
        }
        if( n.length < 6 ) {
            alert('为了你的账号安全，请设置6位以上的密码！');
            $('#newpwd').focus();
            return false;
        }
        if( n == o ) {
        	alert('新密码必须与旧密码不同！');
            $('#newpwd').focus();
            return false;
        }
        if( n != r ) {
            alert('确认密码与新密码不符！');
            $('#re_pwd').focus();
            return false;
        }
        loading = true;
        $.ajax({
            url: '/user/password.html',
            type: 'POST',
            dataType: 'json',
            data: 'oldpwd='+o+'&newpwd='+n+'&re_pwd='+r,
            success: function(msg){
            	loading = false;
                alert(msg.msg);
                if( msg.fwd ) location.href = msg.fwd;
            },
            error: function(){
                loading = false;
                alert('网络连接失败！');
            }
        });
    });
});
</script>
</body>
</html>